import { CustomModel } from '../types';

/**
 * 查找模型
 * @param root 顶层模型
 * @param id
 * @returns
 */
export function findChildModelById(root: CustomModel, id: string): CustomModel | undefined {
  const models: CustomModel[] = [root];
  while (models.length) {
    const model = models.shift()!;
    if (model.id === id) {
      return model;
    } else {
      models.push(...model.getAccessory(), ...model.getChild());
    }
  }
  return undefined;
}
